﻿@{
    ViewBag.Title = "FirstLook";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@{Lang lang = ViewBag.Lang;}
<script src="/Scripts/2012.2.607/telerik.chart.min.js" type="text/javascript"></script>
@model IEnumerable<TGVR_Project.Models.ComparePriceModel>
@(Html.Telerik().Chart(Model)
    .Name("TheFirstWay")
    .Title(title => title
        .Text("Biểu đồ giá vé trong tháng")
        .Visible(ViewBag.ShowTitle)
    )
    .Legend(legend => legend
        .Position(ViewBag.LegendPosition)
        .Visible(ViewBag.ShowLegend)
    )
    .SeriesDefaults(series =>
    {
        series.Bar().Stack(ViewBag.Stack);
        series.Column().Stack(ViewBag.Stack);
        series.Line()
              .Labels(labels => labels.Format("{0:#,##0}").Visible(false).Rotation(90))
              .Stack(ViewBag.Stack);
        series.VerticalLine()
              .Labels(labels => labels.Format("${0:#,##0}").Position(ChartLineLabelsPosition.Right).Visible(true))
              .Stack(ViewBag.Stack);
        series.Area().Stack(ViewBag.Stack);
        series.VerticalArea().Stack(ViewBag.Stack);
    })
    .Series(series =>
    {
        if (ViewBag.SeriesType == "bar")
        {
            series.Bar("VietJetPrice").Name("VietJet Airline");
            series.Bar(s => s.JetstarPrice).Name("Jetstar Airline");
            series.Line(s => s.VietNamPrice).Name("Vietnam Airline");
        }
        else if (ViewBag.SeriesType == "column")
        {
            series.Column("VietJetPrice").Name("VietJet Airline");
            series.Column(s => s.JetstarPrice).Name("Jetstar Airline");
            series.Line(s => s.VietNamPrice).Name("Vietnam Airline");
        }
        else if (ViewBag.SeriesType == "line")
        {
            series.Line("VietJetPrice").Name("VietJet Airline")
                .Markers(markers => markers.Type(ChartMarkerShape.Circle));
            series.Line(s => s.JetstarPrice).Name("Jetstar Airline");
            series.Line(s => s.VietNamPrice).Name("Vietnam Airline");

        }
        else if (ViewBag.SeriesType == "area")
        {
            series.Area(s => s.JetstarPrice).Name("Jetstar Airline");
            series.Area("VietJetPrice").Name("VietJet Airline");
            series.Line(s => s.VietNamPrice).Name("Vietnam Airline");
        }
        else if (ViewBag.SeriesType == "verticalLine")
        {
            series.VerticalLine("VietJetPrice").Name("VietJet Airline")
                .Markers(markers => markers.Type(ChartMarkerShape.Circle));
            series.VerticalLine(s => s.JetstarPrice).Name("Jetstar Airline");
            series.Line(s => s.VietNamPrice).Name("Vietnam Airline");
        }
        else if (ViewBag.SeriesType == "verticalArea")
        {
            series.VerticalArea(s => s.JetstarPrice).Name("Jetstar Airline");
            series.VerticalArea("VietJetPrice").Name("VietJet Airline");
            series.Line(s => s.VietNamPrice).Name("Vietnam Airline");
        }
    })
    .CategoryAxis(axis => axis
        .Categories(s => s.DateString)
    )
    .ValueAxis(axis => axis
        .Numeric().Labels(labels => labels.Format("{0:#,##0} vnd"))
    )
    .Tooltip(tooltip => tooltip
        .Visible(true)
        .Format("{0:#,##0} vnd")
    )
    .DataBinding(dataBinding => dataBinding
                .Ajax().Select("_FirstLook", "testchart")
    )
    .HtmlAttributes(new { style = "width: 900px; height: 400px;" })
            .ClientEvents(e => e.OnDataBinding("showProgress").OnSeriesClick("onSeriesClick"))
)
<script>
    function onSeriesClick(e) {
        alert("onSeriesClick");
    }
    function showProgress(e) {
        $(".loadding").show();
        $("<div class='my-loading'> <img alt='loadding' style='margin: 125px 380px;' class='left' src='/Content/Images/Site/ajax_loader_red_128.gif' /></div>").insertBefore(this.firstChild);
        $(".btnMore").hide();
        //var_dump(e);
    }
</script>
@(Html.Telerik().Chart(Model)
    .Name("chart1")
    .Title(title => title
        .Text("Representative Sales vs. Jetstar")
        .Visible(ViewBag.ShowTitle)
    )
    .Legend(legend => legend
        .Position(ViewBag.LegendPosition)
        .Visible(ViewBag.ShowLegend)
    )
    .SeriesDefaults(series =>
    {
        series.Bar().Stack(ViewBag.Stack);
        series.Column().Stack(ViewBag.Stack);
        series.Line()
              .Labels(labels => labels.Format("${0:#,##0}").Visible(false))
              .Stack(ViewBag.Stack);
        series.VerticalLine()
              .Labels(labels => labels.Format("${0:#,##0}").Position(ChartLineLabelsPosition.Right).Visible(true))
              .Stack(ViewBag.Stack);
        series.Area().Stack(ViewBag.Stack);
        series.VerticalArea().Stack(ViewBag.Stack);
    })
    .Series(series =>
    {
        if (ViewBag.SeriesType == "bar")
        {
            series.Bar("VietJetPrice").Name("VietJet Airline");
            series.Bar(s => s.JetstarPrice).Name("Jetstar Airline");
            series.Line(s => s.VietNamPrice).Name("Vietnam Airline");
        }
        else if (ViewBag.SeriesType == "column")
        {
            series.Column("VietJetPrice").Name("VietJet Airline");
            series.Column(s => s.JetstarPrice).Name("Jetstar Airline");
            series.Line(s => s.VietNamPrice).Name("Vietnam Airline");
        }
        else if (ViewBag.SeriesType == "line")
        {
            series.Line("VietJetPrice").Name("VietJet Airline")
                .Markers(markers => markers.Type(ChartMarkerShape.Circle));
            series.Line(s => s.JetstarPrice).Name("Jetstar Airline");
            series.Line(s => s.VietNamPrice).Name("Vietnam Airline");
        }
        else if (ViewBag.SeriesType == "area")
        {
            series.Area(s => s.JetstarPrice).Name("Jetstar Airline");
            series.Area("VietJetPrice").Name("VietJet Airline");
            series.Line(s => s.VietNamPrice).Name("Vietnam Airline");
        }
        else if (ViewBag.SeriesType == "verticalLine")
        {
            series.VerticalLine("VietJetPrice").Name("VietJet Airline")
                .Markers(markers => markers.Type(ChartMarkerShape.Circle));
            series.VerticalLine(s => s.JetstarPrice).Name("Jetstar Airline");
            series.Line(s => s.VietNamPrice).Name("Vietnam Airline");
        }
        else if (ViewBag.SeriesType == "verticalArea")
        {
            series.VerticalArea(s => s.JetstarPrice).Name("Jetstar Airline");
            series.VerticalArea("VietJetPrice").Name("VietJet Airline");
            series.Line(s => s.VietNamPrice).Name("Vietnam Airline");
        }
    })
    .CategoryAxis(axis => axis
        .Categories(s => s.DateString)
    )
    .ValueAxis(axis => axis
        .Numeric().Labels(labels => labels.Format("{0:#,##0} vnd"))
    )
    .Tooltip(tooltip => tooltip
        .Visible(true)
        .Format("{0:#,##0} vnd")
    )
            .DataBinding(dataBinding => dataBinding
                        .Ajax().Select("_FirstLook1", "testchart")
            )
    .HtmlAttributes(new { style = "width: 900px; height: 400px;" })
        .ClientEvents(e => e.OnDataBinding("showProgress"))
)